var e = require;
var t = module;
var o = exports;
var Adv_skd=require("./Adv_skd");
Object.defineProperty(o, "__esModule", {value: !0});
var n = e("BaseModuleUI"),
    a = e("NotifyEventType"),
    i = e("GlobalParams"),
    r = e("AssetsManager"),
    s = e("CommonHelper"),
    l = e("nameCfg"),
    c = e("UIManager"),
    d = cc._decorator,
    h = d.ccclass,
    _ = d.property,
    u = (function (e) {
        function t() {
            var t = (null !== e && e.apply(this, arguments)) || this;
            return (
                (t.player_node_view = null),
                (t.invite_player_item = null),
                (t.invite_player_view = null),
                (t.match_player_view = null),
                (t.count_down_time = null),
                (t.match_tip_label = null),
                (t.inviter_player = []),
                (t.random_inviter_player = []),
                (t.random_name = []),
                (t.match_random_name = []),
                (t.match_random_hero = []),
                (t.count_down = 0),
                (t.match_over_time = 0),
                t
            );
        }
        return (
            __extends(t, e),

            (t.prototype.onDisable = function () {

                Adv_skd.default.instance.hideBannerAd();
                Adv_skd.default.instance.hideGridAdLeft();
                Adv_skd.default.instance.hideGridAdRight();
                Adv_skd.default.instance.hideGridAdTop();
                Adv_skd.default.instance.hideGridAdLeftOne();
                Adv_skd.default.instance.hideGridAdRightOne();
                Adv_skd.default.instance.hideGridAdButtom();

            }),

            (t.prototype.initView = function () {

                Adv_skd.default.instance.hideBannerAd();
                Adv_skd.default.instance.hideGridAdLeft();
                Adv_skd.default.instance.hideGridAdRight();
                Adv_skd.default.instance.hideGridAdTop();
                Adv_skd.default.instance.hideGridAdLeftOne();
                Adv_skd.default.instance.hideGridAdRightOne();
                Adv_skd.default.instance.hideGridAdButtom();
                Adv_skd.default.instance.showGridAdRightOne();
                Adv_skd.default.instance.showGridAdLeft();
                Adv_skd.default.instance.showBannerAd();
                Adv_skd.default.instance.showInterstitialAd();

                (this.match_player_view.active = !1), this.getMatchPlayer(), this.getInvitePlayer();
            }),
            (t.prototype.getMatchPlayer = function () {
                (this.inviter_player = []), (this.match_random_name = []), (i.GlobalParams.MatchGamePlayer = []);
                var e = i.GlobalParams.PlayerInfo.value;
                this.random_name.push(e.name),
                    this.match_random_name.push(e.name),
                    (this.inviter_player[0] = {
                        name: e.name,
                        head: e.head,
                        role_id: 0,
                        player_skill: [1, 2],
                        dower_info: [0, 0],
                        level: 1,
                        exp_num: 0,
                        kill_info: [0, 0, 0],
                        skill_info: [0, 0],
                        equip_info: [0, 0, 0, 0, 0],
                        coin: 0
                    }),
                    this.showPlayerView();
            }),
            (t.prototype.showPlayerView = function () {
                for (var e = 0; e < this.player_node_view.childrenCount; e++) {
                    var t = this.player_node_view.children[e],
                        o = this.inviter_player[e];
                    (t.getChildByName("player_name").getComponent(cc.Label).string = o ? o.name : ""),
                        (t.getChildByName("head_image").getComponent(cc.Sprite).spriteFrame = o
                            ? r.default.getInstance().getPlayerHeadFrame(o.head)
                            : null),
                        (t.getChildByName("my").active = 0 == e),
                        (t.getChildByName("player_name").color =
                            0 == e ? cc.color(20, 255, 50) : cc.color(255, 255, 255));
                }
            }),
            (t.prototype.OnClick = function (t) {
                switch ((e.prototype.OnClick.call(this, t), t.node.name)) {
                    case "back_btn":
                        (i.GlobalParams.MathcTimeInfo.open = !0), this.node.destroy();
                        break;
                    case "begin_btn":
                        (this.match_player_view.active = !0),
                            (this.count_down = 1),
                            (this.match_over_time = s.default.getRandomInt(3, 6)),
                            this.countDown();
                        var o = s.default.getRandomInt(0, 1);
                        i.GlobalParams.MatchMyIndex = o;
                        for (var n = 0; n < 6; n++)
                            if (n % 2 == o % 2) {
                                var r = n % 2 == 0 ? n / 2 : (n - 1) / 2;
                                this.inviter_player[r]
                                    ? i.GlobalParams.MatchGamePlayer.push(this.inviter_player[r])
                                    : this.addAIPlayer();
                            } else this.addAIPlayer();
                        this.emitEvent(a.default.SEND_COCOS_ANALYTICS, {name: "事件一", info: "接受组队邀请"}),
                            cc.log(this.inviter_player),
                            cc.log(i.GlobalParams.MatchGamePlayer);
                }
            }),
            (t.prototype.getInvitePlayer = function () {
                this.random_inviter_player = [];
                for (var e = 0; e < 10; e++) {
                    var t = {name: "", head: 0, level: 0},
                        o = "";
                    do {
                        o = l.default.nameList[s.default.getRandomInt(0, l.default.nameList.length - 1)];
                    } while (-1 != this.random_name.indexOf(o));
                    this.random_name.push(o),
                        (t.name = o),
                        (t.head = s.default.getRandomInt(1, 19)),
                        (t.level = i.GlobalParams.PlayerInfo.value.level + s.default.getRandomInt(-2, 2)),
                        this.random_inviter_player.push(t),
                        9 == e && this.showInvitePlayer();
                }
            }),
            (t.prototype.showInvitePlayer = function () {
                for (var e = 0; e < this.random_inviter_player.length; e++) {
                    var t = cc.instantiate(this.invite_player_item),
                        o = this.random_inviter_player[e];
                    (t.getChildByName("head_image").getComponent(cc.Sprite).spriteFrame = r.default
                        .getInstance()
                        .getPlayerHeadFrame(o.head)),
                        (t.getChildByName("player_name").getComponent(cc.Label).string = "" + o.name),
                        (t.getChildByName("level").getComponent(cc.Sprite).spriteFrame = r.default
                            .getInstance()
                            .getPlayerLevelExp(o.level > 28 ? 28 : o.level)),
                        (t.name = "invite_" + e),
                        (t.active = !0),
                        t.setParent(this.invite_player_view),
                        t.getChildByName("invite_btn").on("click", this.invitePlayer, this);
                }
            }),
            (t.prototype.invitePlayer = function (e) {
                var t = e.node;
                if (
                    ((t.children[0].getComponent(cc.Label).string = "已邀请"),
                    (t.getComponent(cc.Button).interactable = !1),
                    s.default.getRandomInt(1, 100) < 70 && this.inviter_player.length < 3)
                ) {
                    var o = Number(s.default.getNameType(t.parent.name, "invite_")),
                        n = s.default.getRandomInt(0, 4);
                    this.match_random_name.push(this.random_inviter_player[o].name);
                    var a = 0;
                    do {
                        a =
                            i.GlobalParams.GameHeroIndex[
                                s.default.getRandomInt(0, i.GlobalParams.GameHeroIndex.length - 1)
                            ];
                    } while (-1 != this.match_random_hero.indexOf(a));
                    this.match_random_hero.push(a),
                        (this.inviter_player[this.inviter_player.length] = {
                            name: this.random_inviter_player[o].name,
                            head: this.random_inviter_player[o].head,
                            role_id: a,
                            player_skill: [1, 2],
                            dower_info: [n, i.GlobalParams.PlayerDowerInfo.value.dower[n]],
                            level: 1,
                            exp_num: 0,
                            kill_info: [0, 0, 0],
                            skill_info: [1, 0],
                            equip_info: [0, 0, 0, 0, 0],
                            coin: 0
                        }),
                        this.showPlayerView();
                }
            }),
            (t.prototype.countDown = function () {
                var e = this;
                (this.count_down_time.string = "" + this.count_down), (this.match_tip_label.string = "正在匹配");
                for (var t = 0; t < 3; t++) t < this.count_down % 4 && (this.match_tip_label.string += "。");
                this.count_down < this.match_over_time
                    ? cc
                          .tween(this.count_down_time.node)
                          .to(0.8, {scale: 1})
                          .delay(0.2)
                          .call(function () {
                              (e.count_down_time.node.scale = 0.1), e.count_down++, e.countDown();
                          })
                          .start()
                    : (cc.find("UIManager").getComponent(c.default).showPopup("ChooseHoreViewUI"), this.node.destroy());
            }),
            (t.prototype.addAIPlayer = function () {
                var e = "";
                do {
                    e = l.default.nameList[s.default.getRandomInt(0, l.default.nameList.length - 1)];
                } while (-1 != this.match_random_name.indexOf(e));
                this.match_random_name.push(e);
                var t = 0;
                do {
                    t =
                        i.GlobalParams.GameHeroIndex[
                            s.default.getRandomInt(0, i.GlobalParams.GameHeroIndex.length - 1)
                        ];
                } while (-1 != this.match_random_hero.indexOf(t));
                this.match_random_hero.push(t);
                var o = s.default.getRandomInt(0, 4),
                    n = {
                        name: e,
                        head: s.default.getRandomInt(1, 19),
                        role_id: t,
                        player_skill: [1, 2],
                        dower_info: [o, i.GlobalParams.PlayerDowerInfo.value.dower[o]],
                        level: 1,
                        exp_num: 0,
                        kill_info: [0, 0, 0],
                        skill_info: [1, 0],
                        equip_info: [0, 0, 0, 0, 0],
                        coin: 0
                    };
                i.GlobalParams.MatchGamePlayer.push(n);
            }),
            __decorate([_(cc.Node)], t.prototype, "player_node_view", void 0),
            __decorate([_(cc.Node)], t.prototype, "invite_player_item", void 0),
            __decorate([_(cc.Node)], t.prototype, "invite_player_view", void 0),
            __decorate([_(cc.Node)], t.prototype, "match_player_view", void 0),
            __decorate([_(cc.Label)], t.prototype, "count_down_time", void 0),
            __decorate([_(cc.Label)], t.prototype, "match_tip_label", void 0),
            __decorate([h], t)
        );
    })(n.default);
o.default = u;
